home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.1 / JimmDemos / DemoSource / buildt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  4.8 KB  |  217 lines

  1. /* buildt.c --  autorequest builder test program
  2.  * Copyright (c) 1988, I and I Computing and Commodore-Amiga, Inc.
  3.  *
  4.  *
  5.  * Executables based on this information may be used in software
  6.  * for Commodore Amiga computers.  All other rights reserved.
  7.  *
  8.  * This information is provided "as is"; no warranties are made.
  9.  * All use is at your own risk, and no liability or responsibility is assumed.
  10.  */
  11.  
  12.  
  13. /*
  14.  * This is an old, ugly test program shell.  Sorry about that.
  15.  * It's probably not too good an example to use.
  16.  */
  17.  
  18. #include <exec/types.h>
  19. #include <intuition/intuition.h>
  20.  
  21. #include "getargs.h"
  22.  
  23. struct  Window      *getNewWind();
  24.  
  25. struct  IntuitionBase   *IntuitionBase = NULL;
  26. struct  GfxBase         *GfxBase = NULL;
  27.  
  28. ULONG   flg =   WINDOWCLOSE | NOCAREREFRESH | WINDOWDRAG
  29.                 | WINDOWDEPTH | SIMPLE_REFRESH;
  30.  
  31. ULONG   iflg =  CLOSEWINDOW | MOUSEBUTTONS;
  32.  
  33. BOOL    short_bool =    FALSE;
  34. BOOL    long_bool =        TRUE;
  35. BOOL    arg_bool =        FALSE;
  36.  
  37. struct Arg myargs[] = {
  38.     {'s', ARG_TBOOL, &short_bool, "short strings"},
  39.     {'l', ARG_TBOOL, &long_bool, "medium-long strings"},
  40.     {'a', ARG_TBOOL, &arg_bool, "command-line arguments"},
  41. };
  42.  
  43. /* some short strings */
  44. char   *SReqStrings[] = {
  45.     "P",
  46.     "Q",
  47.     "R",
  48.     NULL
  49. };
  50.  
  51. /* some longer strings */
  52. char   *AReqStrings[] = {
  53.     "Please insert your favorite Tie",
  54.     "into this here disk drive",
  55.     "or you'll never see your mother again.",
  56.     NULL
  57. };
  58.  
  59. char   *retrytext;
  60. char   *canceltext;
  61. char    **reqstrings;
  62.  
  63. main(argc, argv)
  64. char    **argv;
  65. {
  66.     struct  IntuiMessage    *msg;
  67.     struct Window   *window = NULL;
  68.     WORD    exitval = 0;
  69.  
  70.     ULONG result;
  71.     int        argb;
  72.  
  73.     /* hold data from *msg  */
  74.     ULONG   class;
  75.     USHORT  code;
  76.  
  77.     if ((IntuitionBase = 
  78.         (struct IntuitionBase *) OpenLibrary("intuition.library", 0L)
  79.         ) == NULL)
  80.     {
  81.         printf("NO INTUITION LIBRARY\n");
  82.         exitval = 1;
  83.         goto EXITING;
  84.     }
  85.  
  86.     if ((GfxBase = 
  87.         (struct GfxBase *) OpenLibrary("graphics.library", 0L)
  88.         ) == NULL)
  89.     {
  90.         printf("NO GRAPHICS LIBRARY\n");
  91.         exitval = 2;
  92.         goto EXITING;
  93.     }
  94.  
  95.     /* command-line arguments    */
  96.     if ( (argb = getargs( argv, myargs, NUMARGS( myargs ), NULL)) < 0 )
  97.         goto EXITING;
  98.  
  99.     argv += argb;
  100.  
  101.     if ( short_bool )
  102.     {
  103.         reqstrings =  SReqStrings;
  104.         retrytext =    "L";
  105.         canceltext =   "R";
  106.     }
  107.     else if ( arg_bool )
  108.     {
  109.         reqstrings = argv;
  110.         retrytext =    "Left";
  111.         canceltext =   "Right";
  112.     }
  113.     else
  114.     {
  115.         reqstrings =  AReqStrings;
  116.         retrytext =    "This tie?";
  117.         canceltext =   "Keep her";
  118.     }
  119.  
  120.     /* init libraries and window    */
  121.     window = getNewWind(20, 20, 500, 50, flg, iflg);
  122.     if (window == NULL)
  123.     {
  124.         printf("test: SysInit failed.\n");
  125.         exitval = 1;
  126.         goto EXITING;
  127.     }
  128.  
  129.     /* OTHER INIT CODE HERE */
  130.  
  131.     printf("test program ok\n");
  132.  
  133.     FOREVER
  134.     {
  135.         if ((msg = (struct IntuiMessage *)GetMsg(window->UserPort)) == NULL)
  136.         {
  137.             Wait( 1L << window->UserPort->mp_SigBit );
  138.             continue;
  139.         }
  140.  
  141.         /* Stash message contents and reply,
  142.          * important when message triggers some
  143.          * lengthy processing
  144.          */
  145.  
  146.         class   = msg->Class;
  147.         code    = msg->Code;
  148.         ReplyMsg( msg );
  149.  
  150.         switch (class)
  151.         {
  152.         case MOUSEBUTTONS:
  153.             switch( code )
  154.             {
  155.             case SELECTDOWN:
  156.                 printf("MOUSE SELECTDOWN\n");
  157.                 printf("calling buildAutoRequest:\n");
  158.  
  159.                 /* test build function */
  160.                 result = buildAutoRequest( window, reqstrings,
  161.                         retrytext, canceltext, 0L, 0L);
  162.                 printf("result %x\n", result);
  163.  
  164.                 break;
  165.             }
  166. #if LOOPMODE
  167.             break;
  168. #else
  169.             goto EXITING;
  170. #endif
  171.         case CLOSEWINDOW:
  172.             goto EXITING;
  173.         default:
  174.             break;
  175.         }
  176.     }
  177.  
  178. EXITING:
  179.     if (window) CloseWindow(window);
  180.     if (GfxBase) CloseLibrary(GfxBase);
  181.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  182.     exit (exitval);
  183. }
  184.  
  185.  
  186. struct  Window * getNewWind(left, top, width, height, flg, iflg)
  187. SHORT   left, top, width, height;
  188. ULONG   flg, iflg;
  189. {
  190.     struct  Window  *OpenWindow();
  191.     struct  NewWindow   nw;
  192.  
  193.     nw.LeftEdge =   (SHORT) left;
  194.     nw.TopEdge  =   (SHORT) top;
  195.     nw.Width    =   (SHORT) width;
  196.     nw.Height   =   (SHORT) height;
  197.     nw.DetailPen    =   (UBYTE) -1;
  198.     nw.BlockPen =   (UBYTE) -1;
  199.     nw.IDCMPFlags   =   (ULONG) iflg;
  200.  
  201.     nw.Flags    =   (ULONG) flg;
  202.  
  203.     nw.FirstGadget  =   (struct Gadget *)   NULL;
  204.     nw.CheckMark    =   (struct Image *)    NULL;
  205.     nw.Title    =   (UBYTE *)   " Click in Window for AutoRequest";
  206.     nw.Screen   =   (struct Screen *)   NULL;
  207.     nw.BitMap   =   (struct BitMap *)   NULL;
  208.     nw.MinWidth =   (SHORT) 50;
  209.     nw.MinHeight=   (SHORT) 30;
  210.     nw.MaxWidth = nw.MinWidth;
  211.     nw.MaxHeight = nw.MinHeight;
  212.     nw.Type = WBENCHSCREEN;
  213.  
  214.     return ( (struct Window *) OpenWindow( &nw ) );
  215. }
  216.  
  217.